import pytest
from playwright.sync_api import Page, sync_playwright

"""
pytest单元测试
"""


@pytest.fixture
def page():
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False, slow_mo=200)
        context = browser.new_context()
        page = context.new_page()
        yield page
        context.close()
        browser.close()


def test_hello():
    print("hello pytest!")


def test_example(page) -> None:
    page.goto("http://127.0.0.1:34009/xxl-job-admin/toLogin")
    page.get_by_placeholder("请输入登录账号").click()
    page.get_by_placeholder("请输入登录账号").fill("admin")
    page.get_by_placeholder("请输入登录密码").click()
    page.get_by_placeholder("请输入登录密码").fill("123456")
    page.get_by_role("button", name="登录").click()
    print(page.title())